﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Trauberman.SOChat.StarLeaderboard.Data;
using Trauberman.SOChat.StarLeaderboard.Domain;
using Trauberman.SOChat.StarLeaderboard.Services;

namespace Trauberman.SOChat.StarLeaderboard.Scraper
{
	public class StarScraper
	{
		private IStarService _starService;
		private IUserService _userService;
		private IChatroomService _chatService;

		public StarScraper(IStarService starService, IUserService userService, IChatroomService chatService)
		{
			this._starService = starService;
			this._userService = userService;
			this._chatService = chatService;
		}

		public void Run()
		{
			// Initiates the scrape
			DataContext context = new DataContext();

			StarsRequest req = new StarsRequest(_userService, _starService);

			List<Task> tasks = new List<Task>();
			ChatRoom[] chatRooms = _chatService.GetChatRooms().ToArray();
			foreach (ChatRoom room in chatRooms)
			{
				Console.WriteLine("Scraping stars for room {0} {1}", room.SOId, room.Name);

				req.LoadStars(room.SOId);

				//tasks.Add(Task.Factory.StartNew(() => req.LoadStars(room.SOId)));
			}

			//Task.WaitAll(tasks.ToArray());
		}
	}
}
